package cn.jdy.payment.service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.payment.entity.MerchantInfo;
import cn.jdy.payment.entity.Orders;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * 银行个性化业务处理模板
 *
 * @author Zhang Yuyong
 */
public abstract class BankBusiServer extends BaseDao<Orders> {

	@Autowired
	protected OrderService orderService;
	@Autowired
	protected MerchantService merchantService;

	/**
	 * 运行时异常
	 *
	 * @param msg
	 */
	protected static void exception(String msg) {
		throw new RuntimeException(msg);
	}

	/**
	 * 生成各银行个性化订单
	 */
	public abstract Orders placeOrder(Orders order, MerchantInfo merchant) throws UnsupportedEncodingException;

	/**
	 * 各银行个性化通知
	 */
	public abstract Orders notify(Map<String, String> param);

	protected boolean verify(String notifyDate, String amount, Orders order) {
		if(notifyDate == null || notifyDate.length() < 8) return false;
		if(!order.getAmount().equals(amount)) return false;
		return true;
	}

	/**
	 * 将null转换为""
	 *
	 * @param str
	 * @return
	 */
	protected String conver(String str) {
		return str == null ? "" : str;
	}
}
